﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ThucHanh2
{
    public partial class Form1 : Form
    {
        List<HocSinh> dsHocSinh;
        public Form1()
        {
            InitializeComponent();
        }

        private void lbDanhSach_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbDanhSach.SelectedIndex >= 0)
            {
                int i = lbDanhSach.SelectedIndex;
                txtTen.Text = dsHocSinh[i].Ten;
                txtDiaChi.Text = dsHocSinh[i].DiaChi;
                cbLop.SelectedText = dsHocSinh[i].Lop;
                dtpNgaySinh.Value = dsHocSinh[i].NgaySinh;
                if (dsHocSinh[i].GioiTinh)
                    rbNam.Checked = true;
                else
                    rbNu.Checked = true;
            }
        }

        private void rbNu_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dsHocSinh = new List<HocSinh>();
            cbLop.Items.Add("09CT1");
            cbLop.Items.Add("09CT2");
            cbLop.SelectedIndex = 0;
        }

        private void bThem_Click(object sender, EventArgs e)
        {
            HocSinh hs = new HocSinh();
            hs.Ten = txtTen.Text;
            hs.Lop = cbLop.SelectedText;
            hs.DiaChi = txtDiaChi.Text;
            hs.GioiTinh = rbNam.Checked;
            hs.NgaySinh = dtpNgaySinh.Value;
            dsHocSinh.Add(hs);
            lbDanhSach.Items.Add(hs.Ten);
        }

        private void bSua_Click(object sender, EventArgs e)
        {
            if (lbDanhSach.SelectedIndex >= 0)
            {
                int i = lbDanhSach.SelectedIndex;
                dsHocSinh[i].Ten = txtTen.Text;
                dsHocSinh[i].DiaChi = txtDiaChi.Text;
                dsHocSinh[i].Lop = cbLop.SelectedText;
                dsHocSinh[i].NgaySinh = dtpNgaySinh.Value;
                dsHocSinh[i].GioiTinh = rbNam.Checked;
                lbDanhSach.Items.RemoveAt(i);
                lbDanhSach.Items.Insert(i, dsHocSinh[i].Ten);
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn học sinh!!!", "Thông báo");
            }
        }

        private void bXoa_Click(object sender, EventArgs e)
        {
            if (lbDanhSach.SelectedIndex >= 0)
            {
                int i = lbDanhSach.SelectedIndex;
                lbDanhSach.Items.RemoveAt(i);
                dsHocSinh.RemoveAt(i);
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn học sinh!!!", "Thông báo");
            }
        }


    }
}
